package eu.jpereira.trainings.designpatterns.structural.facade;

import eu.jpereira.trainings.designpatterns.structural.facade.model.Book;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Customer;
import eu.jpereira.trainings.designpatterns.structural.facade.model.DispatchReceipt;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Order;
import eu.jpereira.trainings.designpatterns.structural.facade.service.BookDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerNotificationService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.OrderingService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.WharehouseService;

public class DefaultBooktoreFacade implements BookstoreFacade
{
    protected CustomerDBService           customerService;
    protected BookDBService               bookService;
    protected OrderingService             orderingService;
    protected CustomerNotificationService customerNotificationService;
    protected WharehouseService           warehouseService;

    public DefaultBooktoreFacade()
    {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void placeOrder(String customerId, String isbn)
    {
        Book book = this.bookService.findBookByISBN(isbn);
        Customer customer = this.customerService.findCustomerById(customerId);
        Order order = this.orderingService.createOrder(customer, book);
        DispatchReceipt dispatch = this.warehouseService.dispatch(order);
        this.customerNotificationService.notifyClient(dispatch);
    }

    public void setCustomerService(CustomerDBService service)
    {
        this.customerService = service;
    }

    public void setBookDBService(BookDBService service)
    {
        this.bookService = service;
    }

    public void setOrderingService(OrderingService service)
    {
        this.orderingService = service;
    }

    public void setCustomerNotificationService(
            CustomerNotificationService service)
    {
        this.customerNotificationService = service;
    }

    public void setWarehouseService(WharehouseService service)
    {
        this.warehouseService = service;
    }

}
